package leetcode100;

// TODO 递归+回溯+剪枝 [经典] 【-】 子集
// TODO https://leetcode.cn/problems/subsets/solution/shou-hua-tu-jie-zi-ji-hui-su-fa-xiang-jie-wei-yun-/

import java.util.ArrayList;
import java.util.List;

public class lc100_0078 {

    List<List<Integer>> res = new ArrayList<>();
    List<Integer> path = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        // 先添加一个空集
        res.add(new ArrayList<>(path));

        dfs(nums, 0);
        return res;
    }

    public void dfs(int[] nums, int index) {
        // 递归结束控制器
        if (index >= nums.length) {
            return;
        }
        // 递归
        for (int i = index; i < nums.length; i++) {
            path.add(nums[i]);
            dfs(nums, i+1);
            // 回溯
            path.remove(path.size() - 1);
        }

    }

}
